/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admintool.imp03_data;

import admintool.AdminToolView;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author Administrator
 */
public class IMP03_Qualification {

    private class Qualification{

        private int qualificationID = 0;
        private String qualificationName = "";
        
        public Qualification(int qualificationID, String qualificationName) {
            this.qualificationID = qualificationID;
            this.qualificationName = qualificationName;
        }

        public int getQualificationID() {
            return qualificationID;
        }

        public String getQualificationName() {
            return qualificationName;
        }
    }
    
    private static ArrayList<IMP03_Qualification> qualifications = new ArrayList<IMP03_Qualification>();
    
    /**
     * 
     * @return
     */
    public static IMP03_Qualification getEmptyQualificationObject(){
        return new IMP03_Qualification(-1, AdminToolView.EMPTY);
    }
    
    /**
     * 
     * @param reload
     * @return
     */
    public static ArrayList<IMP03_Qualification> getAllAvailableQualificationsFromDB(boolean reload){
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            if(reload == true || qualifications.isEmpty()){
                qualifications.clear();
                ps = AdminToolView.getDBConnection().prepareStatement("SELECT * FROM qualification");
                rs = ps.executeQuery();
                while(rs.next()){
                    qualifications.add(new IMP03_Qualification(rs.getInt(1), rs.getString(2)));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(rs != null){
                    rs.close();
                }
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e) {
            }
        }
        return qualifications;
    }
    
    private Qualification qualificication = null;
    
    /**
     * 
     * @param qualificationID
     * @param qualificationName
     */
    public IMP03_Qualification(int qualificationID, String qualificationName) {
        this.qualificication = new Qualification(qualificationID, qualificationName);
    }
    
    /**
     * 
     * @return
     */
    public int getQualificationID(){
        return qualificication.getQualificationID();
    }

    /**
     * 
     * @return
     */
    public String getQualificationName(){
        return qualificication.getQualificationName();
    }

    @Override
    public String toString() {
        return qualificication.getQualificationName();
    }
}
